<template>
<div>
	<div class="g_top_box">
		<div class="g_right_box">
			<Button type="primary" @click="$router.push({name:'bumen_add',params:{id:id}})">添加</Button>
		</div> 
		<div class="g_left_box"><h4>部门列表</h4></div>
	</div>
	
	<div class="g_list_box">
		<div class="g_filter_box">
			<Form ref="formDynamic" :label-width="50" style="width: 100%">
				<Input v-model="filter.name" placeholder="名称" style="width:130px;"></Input>
				<Button type="primary" @click="qurey">搜索</Button>
			</Form>
		</div>
		<div class="g_list_box">
			<Table :columns="Columns" :data="list" style="width: 100%;"></Table>
		</div>
		<div class="g_page_box">
			<Page :total="count" @on-change="goto_page"></Page>
		</div>
	</div>
	
	
</div>
</template>

<script>
export default {
    name: 'bumen_list',
    data () {
		let vm = this;
        return {
            Columns: [
				{
					title: 'ID',
					key: 'id',
					align: 'center',
                    width: 80
                },
				{
                    title: '名称',
					key: 'name',
					width: 200,
                },
				{
                        title: '操作',
                        key: 'action',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small',
										icon:'edit'
                                    },
                                    style: {
                                        marginRight: '5px',
                                    },
                                    on: {
                                        click: () => {
											
											this.$router.push({name:'bumen_info',params:{'id':params.row.id}});
                                            //this.show(params.index)
                                        }
                                    }
                                }, '编辑'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small',
										icon:'trash-a'
                                    },
									style: {
										display:params.row.username =='admin'?'none':'inline-block'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.row.id)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
            ],
            list: [],
			count:0,
			page:1,
			filter:{
				name:'',
				company_id:0
			},
			id:0
        };
    },
	created(){
		this.id = this.$route.params.id;
		this.load_data();
	},
    computed: {
       
    },
	methods:{
		load_data(){
			var self = this;
			this.filter['company_id'] = this.id;
			var postdata = {
				f:this.filter,
				page:this.page
			}
			
			Whttp.load('User/Bumen/get_list',postdata,function(result){
				self.list = result.list;
				self.count = parseInt(result.count);
			});
		},
		remove(id){
			if(!confirm('是否删除')){
				return;
			}
			var self = this;
			var postdata = {
				id:id
			};
			Whttp.load('User/Bumen/del',postdata,function(result){
				self.load_data();
			});
		},
		goto_page(page){
			this.page = page;
			this.load_data();
		},
		qurey(){
			this.page = 1;
			this.load_data();
		}
	}
};
</script>